package com.example.wangyi.base;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;


import com.example.wangyi.manager.ContainManager;
import com.example.wangyi.utils.StatusBarUtils;

import butterknife.ButterKnife;
import butterknife.Unbinder;

public abstract class BaseActivity<P extends BasePresenter, T> extends AppCompatActivity implements BaseView<T> {
    private Unbinder mBind;
    private P mPersenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtils.setColor(this,0x000000);
        StatusBarUtils.setTextDark(this,true);
        int layoutId = getLayoutId();
        if (layoutId != 0)
            setContentView(layoutId);
        mBind = ButterKnife.bind(this);
        ContainManager.getmManager().addActivity(this);
        mPersenter = createPresenter();
        if (mPersenter != null) {
            mPersenter.attachView(this);
        }
        init();
        initData();
    }

    protected abstract P createPresenter();

    protected P getmPersenter() {
        if (mPersenter != null) {
            return mPersenter;
        }
        return null;
    }

    protected abstract void initData();

    protected abstract void init();



    protected abstract int getLayoutId();

    @Override
    public void onSuccess(T t) {

    }

    @Override
    public void onError(String msg) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mBind != null) {
            mBind.unbind();
        }
        if (mPersenter != null) {
            mPersenter.dettachView();
            mPersenter = null;
        }
    }
}
